package com.yunyao.dao.service.bamu.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.yunyao.common.constant.enums.DataDeletedStatus;
import com.yunyao.dao.model.BamuPoSupplyMaterial;
import com.yunyao.dao.mapper.BamuPoSupplyMaterialMapper;
import com.yunyao.dao.model.BamuReconciliationOrder;
import com.yunyao.dao.model.BamuSpReconciliationOrderMaterial;
import com.yunyao.dao.service.bamu.IBamuPoSupplyMaterialService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 合同材料表 服务实现类
 * </p>
 *
 * @author xingjishuai
 * @since 2024-07-02
 */
@Service
public class BamuPoSupplyMaterialServiceImpl extends ServiceImpl<BamuPoSupplyMaterialMapper, BamuPoSupplyMaterial> implements IBamuPoSupplyMaterialService {

    @Override
    public List<BamuPoSupplyMaterial> listByIdsDeleted(List<String> MaterialIdList) {
        // 检查对账ID列表是否为空，如果为空则直接返回空列表
        if (CollectionUtils.isEmpty(MaterialIdList)) {
            return List.of();
        }

        // 创建查询条件封装Lambda表达式，用于筛选特定条件的对账结算单
        LambdaQueryWrapper<BamuPoSupplyMaterial> wrapper =
                new LambdaQueryWrapper<BamuPoSupplyMaterial>()
                        // 条件1：清单ID在给定的列表中
                        .in(BamuPoSupplyMaterial::getSupplyId, MaterialIdList)
                        // 条件2：对账单的删除状态为未删除
                        .eq(BamuPoSupplyMaterial::getIsDeleted, DataDeletedStatus.NO.getType());

        // 使用封装的查询条件，查询并返回对账单列表
        return list(wrapper);
    }

    @Override
    public List<BamuPoSupplyMaterial> listBySupplyId(String contrentId) {
        return null;
    }

    @Override
    public List<BamuPoSupplyMaterial> listByReconciliationId(String supplyId) {
        // 检查对账ID是否为空或空白，如果是，则直接返回一个空列表
        if (StringUtils.isBlank(supplyId)) {
            return List.of();
        }
        // 构建查询条件，包括对账ID和材料未被删除的状态
        LambdaQueryWrapper<BamuPoSupplyMaterial> wrapper =
                new LambdaQueryWrapper<BamuPoSupplyMaterial>().eq(BamuPoSupplyMaterial::getSupplyId, supplyId)
                        .eq(BamuPoSupplyMaterial::getIsDeleted,
                                DataDeletedStatus.NO.getType());
        // 执行查询并返回结果
        return list(wrapper);
    }
}
